<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.pro.bean.Groups " %>
<%@ page import="com.pro.bean.Users" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<head>
    <base href="<%=basePath%>">
    <meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
 
	<link href="css/bootstrap.css" rel="stylesheet">
	<link rel="stylesheet" href="css/main.css">

	<script src="js/jquery.js"></script>
	<script src="js/bootstrap.min.js"></script>

	<title>组一览</title>
<script type="text/javascript">

   function deleteGroup(groupid){
   var flag=window.confirm("确定删除？");
   if(flag==true)
    $.ajax({
    type:"post",
    url:"GroupServlet?&status=deleteGroup&groupid="+groupid,
    data:$("#formleft").serialize(),
    success:function(datas){
    parent.frames["left"].location.reload();
    }
    });
    }
 
    function CheckId(groupid){	
       var flag=window.confirm("确定更新？"); 
      if(flag==true){	
			window.location.href="jsp/groupInfo.jsp?groupid="+groupid;
			 }
		}
</script>
</head>
<%
  ArrayList<Groups> gps = (ArrayList<Groups>) request.getSession().getAttribute("groups");
    int intPageSize=6;  //每页显示的记录数
	int currPageBegin;  //起始记录索引	
	int AllPage;   //总页数
	int requestPage;     //用户请求页码
	String strPage;
	
	 strPage=request.getParameter("pagenumber");
	 if(strPage==null)
	 {
	 requestPage=1;
	 }
	 else
	 {
	    requestPage=Integer.parseInt(strPage);
	    if(requestPage<1)
	   {
	    requestPage=1;
	    }
	 
	 }
	 AllPage=(gps.size()+intPageSize-1)/intPageSize;
	 if(requestPage>AllPage)
	    requestPage=AllPage;
	currPageBegin=requestPage*intPageSize-intPageSize;	
	
  
	if(gps == null||gps.size()==0)
		out.println("组为空");
 %>

<body>
<form  action="GroupServlet" name="formleft" id="formleft">
   <div id="leftdiv"  style="width:390px" >
	<legend>
	<font color="#FF0000" size="2">组一览</font>
	</legend>
	<table class="table table-bordered table-hover">
		<tr>
			<th>组名</th>
			<th>父组名</th>
			<th>共同所有</th>
			<th>所有者</th>
			<th>删除</th>
			<th>更新</th>
		</tr>
		
		<%
			for(int i=currPageBegin; i < requestPage*intPageSize&&i<gps.size();i++){
		 %>
		<tr>
	
			<td ><a href="CardGroupServlet?groupname=<%=gps.get(i).getGroupname() %>" target="right"><%=gps.get(i).getGroupname() %></a></td>
			<td ><%=gps.get(i).getPrgroupid() %></td>
			<td>非共有</td>
			 <td><%=((Users)request.getSession().getAttribute("Users")).getUsername() %></td>
			<td><a href="javascript:deleteGroup(<%=gps.get(i).getGroupid()%>)">删除</a></td>
			<td><a href="javascript:CheckId(<%=gps.get(i).getGroupid()%>)">更新</a></td>
		</tr>
		<%} %>
	</table>
         
         <center>
                               共<%=AllPage%>页&nbsp;第<%=requestPage%>页        
          <%if(requestPage>1){ %>
            <a href="jsp/groupLeft.jsp?pagenumber=<%=requestPage-1%>">上一页</a>
            <%}else{ %>
                                    上一页
         <%}%>
         <%if(requestPage<AllPage){ %>
        <a href="jsp/groupLeft.jsp?pagenumber=<%=requestPage+1%>">下一页</a>
            <%}else{ %>
                                   下一页
         <%}%>
         </center>      

</div>
</form>
</body>
</html>

